@ECHO OFF

set WORKDIR=%CD%

REM 7zip path
set PATH=%PATH%;"C:\Program Files\7-Zip\";%WORKDIR%\cmake\cmake-2.8.5-win32-x86\bin

REM ---------- CMake
IF EXIST cmake\cmake-2.8.5-win32-x86 ( goto L_CHECK_CMAKE_EXTRACT_END )
echo extracting CMake...
7z.exe x -ocmake pack.tool\cmake-2.8.5-win32-x86.zip

:L_CHECK_CMAKE_EXTRACT_END

REM ---------- swig
IF EXIST swig\swigwin-2.0.4 ( goto L_CHECK_SWIG_EXTRACT_END )
echo extracting swig...
7z.exe x -oswig pack.tool\swigwin-2.0.4.zip

:L_CHECK_SWIG_EXTRACT_END

REM ---------- cppunit
IF EXIST cppunit\cppunit-1.12.1 ( goto L_CHECK_CPPUNIT_EXTRACT_END )
echo extracting cppunit...
7z.exe x -ocppunit pack.src\cppunit-1.12.1.tar.gz
7z.exe x -ocppunit cppunit\cppunit-1.12.1.tar
del /S /Q cppunit\cppunit-1.12.1.tar


:L_CHECK_CPPUNIT_EXTRACT_END

REM ---------- curl
IF EXIST curl\curl-7.22.0 ( goto L_CHECK_CURL_EXTRACT_END )
echo extracting curl...
7z.exe x -ocurl pack.src\curl-7.22.0.tar.bz2
7z.exe x -ocurl curl\curl-7.22.0.tar
del /S /Q curl\curl-7.22.0.tar


:L_CHECK_CURL_EXTRACT_END

REM ---------- ICU
IF EXIST icu\icu ( goto L_CHECK_ICU_EXTRACT_END )
echo extracting ICU...
7z.exe x -oicu pack.src\icu4c-4_4_2-src.zip

:L_CHECK_ICU_EXTRACT_END


REM ---------- OGRE Dependencies
IF EXIST ogre\Dependencies ( goto L_CHK_OGRE_DEPENDENCIES_EXTRACT_END )
echo extracting OGRE Dependencies...
7z.exe x -oogre pack.src\OgreDependencies_MSVC_20101231.zip

:L_CHK_OGRE_DEPENDENCIES_EXTRACT_END


IF NOT "%1"=="full" (goto TMP_END)

echo "Begin full building procedure..."


REM ---------- Boost

IF EXIST boost\boost_1_47_0 ( goto L_CHK_BOOST_EXTRACT_END )
echo extracting boost...
REM extract boost
7z.exe x -oboost pack.src\boost_1_47_0.7z
:L_CHK_BOOST_EXTRACT_END

IF EXIST sdk\include\boost-1_47 ( goto L_CHK_BOOST_BUILD_END )
cd boost\boost_1_47_0
call bootstrap.bat
REM .\b2 toolset=msvc-9.0express -sHAVE_ICU=1 -sICU_PATH=%WORKDIR%\icu\icu --build-type=complete install --prefix=%WORKDIR%\sdk
popd
.\b2 toolset=msvc-9.0 -sHAVE_ICU=1 -sICU_PATH=%WORKDIR%\icu\icu --build-type=complete install --prefix=%WORKDIR%\sdk
cd %WORKDIR%
:L_CHK_BOOST_BUILD_END


REM ---------- OGRE

IF EXIST ogre\ogre_src_v1-7-3 ( goto L_CHK_OGRE_EXTRACT_END )
echo extracting ogre...
7z.exe x -oogre pack.src\ogre_src_v1-7-3.exe
:L_CHK_OGRE_EXTRACT_END

IF EXIST sdk\include\OGRE ( goto L_CHK_OGRE_BUILD_END )
set BOOST_ROOT=%WORKDIR%\boost\boost_1_47
set OGRE_DEPENDENCIES_DIR=%WORKDIR%\ogre
pushd ogre
IF EXIST buildogre ( rd /S /Q buildogre )
mkdir buildogre
pushd buildogre
cmake -DCMAKE_INSTALL_PREFIX=%WORKDIR%\sdk -G "Visual Studio 9 2008" ..\ogre_src_v1-7-3
popd
cmake --build buildogre --config "Debug|Win32" -- /project INSTALL
cmake --build buildogre --config "Release|Win32" -- /project INSTALL
cmake --build buildogre --config "MinSizeRel|Win32" -- /project INSTALL
cmake --build buildogre --config "RelWithDebInfo|Win32" -- /project INSTALL
popd

:L_CHK_OGRE_BUILD_END

:TMP_END

@pause
